const state = {
	location: null,
	lastUpdated: null,
	selectedAddress: null

}

const mutations = {
	SET_LOCATION(state, payload) {
		state.location = payload
		state.lastUpdated = new Date().getTime()
	},
	// 新增设置完整地址的mutation
	SET_SELECTED_ADDRESS(state, payload) {

		state.selectedAddress = payload;
		state.lastUpdated = new Date().getTime();
	}
}
const actions = {
	updateLocation({
		commit
	}, location) {
		commit('SET_LOCATION', {
			longitude: location.longitude,
			latitude: location.latitude,
			address: location.address,
			city: location.city,
			district: location.district
		})
	},
	updateSelectedAddress({
		commit
	}, address) {
		commit('SET_SELECTED_ADDRESS', {
			contactName: address.contactName, // 保持与表单一致
			contactPhone: address.contactPhone, // 保持与表单一致

			address: address.address || '', // 详细地址
			longitude: address.longitude,
			latitude: address.latitude
		})
	}
}

const getters = {
	currentLocation: state => state.location,
	lastUpdated: state => state.lastUpdated,
	currentAddress: state => state.selectedAddress, // 新增获取完整地址的getter
}

export default {
	namespaced: true,
	state,
	mutations,
	actions,
	getters
}